package com.dap.cas.config;

import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.cas.CasRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.PostConstruct;

/**
 * @description: 类描述
 * @author: Fesine
 * @createTime:2017/12/12
 * @update:修改内容
 * @author: Fesine
 * @updateTime:2017/12/12
 */
public class MyShiroCasRealm extends CasRealm {
    private static final Logger logger = LoggerFactory.getLogger(MyShiroCasRealm.class);

    @Autowired
    private SpringCasConfigProperties autoconfig;

    @PostConstruct
    public void initProperty() {
        setCasServerUrlPrefix(autoconfig.getCasServerUrlPrefix());
        //// 客户端回调地址
        setCasService(autoconfig.getClientUrlPrefix() + autoconfig.getCasFilterUrlPattern());
    }


    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
        logger.info("##################执行Shiro权限认证##################");
        //获取当前登录输入的用户名，等价于(String) principalCollection.fromRealm(getName()).iterator().next();
        String loginName = (String) super.getAvailablePrincipal(principalCollection);
        return new SimpleAuthorizationInfo();
    }
}
